<template>
  <div class="login_upDown">
    <div class="login_title">
      <h1>LET管理系统</h1>
      <h3>LET  MANAGEMENT  SYSTEM</h3>
    </div>
    <div class="container_box" :class="flag?'right-panel-active':''">
      <!-- Sign Up -->
      <div class="container_form container--signUp">
        <form action="#" class="form" id="form1">
          <h2 class="form__title">Sign Up</h2>
          <input type="text" placeholder="User" class="input" />
          <input type="email" placeholder="Email" class="input" />
          <input type="password" placeholder="Password" class="input" />
          <button class="btn" @click="signUp">登出</button>
        </form>
      </div>

      <!-- Sign In -->
      <div class="container_form container_signIn">
        <div class="form">
          <Form ref="formInline" :model="formInline" :rules="ruleInline">
            <h2 class="form__title">Sign In</h2>
            <Form-item prop="userName" style="width: 260px;">
              <Input v-model="formInline.userName" placeholder="用户名/账号" size="large" @on-enter="handleLogin('formInline')"></Input>
            </Form-item>
            <Form-item prop="password">
              <Input size="large" type="password" v-model="formInline.password" placeholder="密码" @on-enter="handleLogin('formInline')"></Input>
            </Form-item>
            <div class="link_b">
              <a class="link" @click="jumpPath('/backPwd')">忘记密码?</a>
            </div>
            <Button @click="handleLogin('formInline')" :loading="loading">登录</Button>
          </Form>
        </div>
      </div>

      <!-- Overlay 覆盖-->
      <div class="container__overlay">
        <div class="overlay">
          <div class="overlay__panel overlay--left">
            <button class="btn" id="signIn" @click="flag = !flag">Sign In</button>
          </div>
          <div class="overlay__panel overlay--right">
            <button class="btn" id="signUp" @click="flag = !flag">Sign Up</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "login_upDown",
    data() {
      return {
        flag: false,
        loading: false,
        formInline: {
          userName: '',
          password: ''
        },
        ruleInline: {
          userName: [
            { required: true, message: '请填写用户名', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请填写密码', trigger: 'blur' },
            { type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
          ]
        },
      }
    },
    created() {

    },
    methods: {
      handleLogin(name) {
        this.$refs[name].validate((valid) => {
          if (valid) {
            this.loading = true;
            this.$store.dispatch('Login', this.formInline).then(res => {
              console.log(res);
              this.loading = false;
              if(res && res.status) {
                if(this.fromUrl) {
                  this.$router.push({
                    path: this.fromUrl
                  })
                }else{
                  this.$router.push({
                    path: '/'
                  })
                }
              }
            })
          } else {
            this.$Message.error('请填写正确用户名或密码!');
          }
        })
      },
      signUp() {
        this.$Message.info('登出');
      },
      jumpPath(path) {
        let that = this;
        that.$router.push({
          path: path
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .login_upDown {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: url("https://res.cloudinary.com/dci1eujqw/image/upload/v1616769558/Codepen/waldemar-brandt-aThdSdgx0YM-unsplash_cnq4sb.jpg") no-repeat fixed center;
    /* 设置背景图像是否固定或者随着页面的其余部分滚动。 */
    background-size: cover;
    display: grid;
    /* CSS place-items 属性分别设置align-items和justify-items属性。如果未设置第二个值，则第一个值也将用于该值。 */
    place-items: center;
    position: relative;
    .login_title{
      position: absolute;
      top: 12%;
      left: 50%;
      height: 90px;
      width: 300px;
      transform: translate(-50%, 0);
      text-align: center;
      @-webkit-keyframes jump{
        30% {transform: translateY(2%) scaleY(0.9);}
        50% {transform: translateY(-100%) scaleY(1.2);}
        70% {transform: translateY(10%) scaleY(0.8);}
        90% {transform: translateY(-5%) scaleY(1);}
        100% {transform: translateY(0) scaleY(1);}
      }
      @keyframes jump{
        30% {transform: translateY(2%) scaleY(0.9);}
        50% {transform: translateY(-100%) scaleY(1.2);}
        70% {transform: translateY(10%) scaleY(0.8);}
        90% {transform: translateY(-5%) scaleY(1);}
        100% {transform: translateY(0) scaleY(1);}
      }
      .jump{
        -webkit-animation-name:jump;
        animation-name:jump
      }
      h1{
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        margin-bottom: 20px;
        text-align: center;
        -webkit-animation: jump 1s ease 0s 3 both;
        font-size: 40px;
      }
      h3{
        position: absolute;
        bottom: 10px;
        left: 50%;
        width: 100%;
        transform: translate(-50%, 0);
      }
    }
    .container_box {
      box-shadow: 0 0.9rem 1.7rem rgba(0, 0, 0, 0.25), 0 0.7rem 0.7rem rgba(0, 0, 0, 0.22);
      background: #e9e9e9;
      height: 420px;
      width: 758px;
      overflow: hidden;
      position: absolute;
      top: 30%;
      left: 50%;
      transform: translate(-50%, 0);
      border-radius: 8px;
      .container_form {
        height: 100%;
        position: absolute;
        top: 0;
        /* 过渡 */
        transition: all 0.6s ease-in-out;
        .form {
          background-color: #e9e9e9;
          display: flex;
          align-items: center;
          justify-content: center;
          flex-direction: column;
          padding: 0 3rem;
          height: 100%;
          text-align: center;
          .form__title {
            font-weight: 300;
            margin: 0 0 2rem 0;
          }
          /deep/ .ivu-input{
            border-radius: 0;
            line-height: 2;
            border: none;
          }
          .input {
            background-color: #fff;
            border: none;
            padding: 0.9rem 0.9rem;
            margin: 0.5rem 0;
            width: 300px;
          }
          .link_b{
            margin-bottom: 1.25rem;
            .link {
              color: #333;
              font-size: 0.9rem;
              padding-bottom: 20px;
              text-decoration: none;
            }
          }
          .btn {
            margin-top: 1.5rem;
          }
          .btn:active {
            transform: scale(0.95);
          }
          .btn:focus {
            outline: none;
          }
        }
      }
      .container_signIn {
        left: 0;
        width: 50%;
        z-index: 2;
      }
      .container--signUp {
        left: 0;
        opacity: 0;
        width: 50%;
        z-index: 1;
      }
      .container__overlay {
        width: 50%;
        height: 100%;
        overflow: hidden;
        position: absolute;
        top: 0;
        left: 50%;
        transition: transform 0.6s ease-in-out;
        z-index: 100;
        text-align: center;
        /*border: 1px solid red;*/
        .overlay {
          background-color: #008997;
          background: url("https://res.cloudinary.com/dci1eujqw/image/upload/v1616769558/Codepen/waldemar-brandt-aThdSdgx0YM-unsplash_cnq4sb.jpg") no-repeat fixed left 0 center;
          background-size: cover;
          height: 100%;
          left: -100%;
          position: relative;
          transform: translateX(0);
          transition: transform 0.6s ease-in-out;
          width: 200%;
          .overlay__panel {
            align-items: center;
            display: flex;
            flex-direction: column;
            height: 100%;
            justify-content: center;
            position: absolute;
            text-align: center;
            top: 0;
            transform: translateX(0);
            transition: transform 0.6s ease-in-out;
            width: 50%;
          }
          .overlay--right {
            right: 0;
          }
        }
      }
      .btn,
      /deep/ .ivu-btn{
        background-color: #0367a6;
        background-image: linear-gradient(90deg, #0367a6 0%, #008997 74%);
        border-radius: 20px;
        border: 1px solid transparent;
        color: #e9e9e9;
        cursor: pointer;
        font-size: 0.8rem;
        font-weight: bold;
        letter-spacing: 0.1rem;
        padding: 0.9rem 4rem;
        /* 控制文本的大小写。 uppercase定义仅有大写字母。 */
        text-transform: uppercase;
        transition: transform 80ms ease-in;
      }
    }
    .right-panel-active {
      .container_signIn {
        transform: translateX(100%);
      }
      .container--signUp {
        animation: show 0.6s;
        opacity: 1;
        transform: translateX(100%);
        z-index: 5;
      }
      .container__overlay {
        transform: translateX(-100%);
        .overlay {
          transform: translateX(50%);
          background-position: left 50% center;
        }
      }
    }
  }

  @keyframes show {

    0%,
    49.99% {
      opacity: 0;
      z-index: 1;
    }

    50%,
    100% {
      opacity: 1;
      z-index: 5;
    }
  }
</style>
